<template>
  <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false"
             v-dialogDrag>

    <div class="app-container">
      <el-button @click="handleAddUser" icon="el-icon-plus" plain size="mini" type="primary">分配人员
      </el-button>
      <el-table border v-loading="loading" :data="dataList" ref="table"
                :max-height="tableMaxHeight">
        <el-table-column  align="center" label="姓名" prop="userName"/>
        <el-table-column  align="center" label="工序名称" prop="name"/>
        <el-table-column  align="center" label="图纸号" prop="shuoming"/>
        <el-table-column  align="center" label="产品编码" prop="goodsCode"/>
        <el-table-column  align="center" label="产品名称" prop="goodsName" show-overflow-tooltip/>
        <el-table-column  align="center" label="产品型号" prop="goodsModel"/>
        <!--<el-table-column align="center" label="型号明细" prop="goodsBrand"/>-->
        <el-table-column align="center" label="单价" prop="money"/>
        <el-table-column align="center" label="分配数量" prop="count"/>
        <el-table-column align="center" label="已完成数量" prop="finishCount"/>
        <el-table-column align="center" label="总价" prop="allMoney"/>
        <el-table-column align="center" label="计划完成时间" prop="planEndTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.planEndTime, '{y}-{m}-{d} ') }}</span>
          </template>
        </el-table-column>
        <!--<el-table-column align="center" label="实际完成时间" prop="doEndTime"/>-->
        <el-table-column align="center" label="备注" prop="remark"/>
        <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleModifyUser(scope.row)" icon="el-icon-view" size="mini" type="text">
              修改
            </el-button>
            <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                           style="margin-left: 10px;">
              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete" >删除</el-button>
            </el-popconfirm>
            <el-button @click="baogong(scope.row)" icon="el-icon-view" size="mini" type="text">
              报工
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <addUseForm-list @ok="getList" ref="addUseForm"></addUseForm-list>
      <modifyUseForm-list @ok="getList" ref="modifyUseForm"></modifyUseForm-list>
      <baogongForm-list @ok="getList" ref="baogongForm"></baogongForm-list>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @pagination="getList"/>
    </div>
  </el-dialog>
</template>

<script>
  import {deleteAction, downloadFile, getAction, getById} from '@/api/manage'
  import AddUseFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/AddUseFormList";
  import ModifyUseFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/ModifyUseFormList";
  import BaogongFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/BaogongFormList";

  export default {
    name: "FeipeiPeopleFormList",
    dicts: ['churuku_type'],
    components: {
      AddUseFormList,
      ModifyUseFormList,
      BaogongFormList,
    },
    data() {
      return {
        title: "分配任务",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        remainCount: null,
        parentId: null,
        money: null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          saleId: null,
          parentId: null,
          goodsId: null,
          goodsName: null,
          goodsBrand: null,
          goodsUnitPrice: null,
          goodsCount: null,
          dateRange: "",
          params: {},
        },
        url: {
          listByParentId: '/goodsSaledoGongxuUser/goodsSaledoGongxuUser/list',
          removeUpdate:'/goodsSaledoGongxuUser/goodsSaledoGongxuUser/removeUpdate/',
        },
        PrjNameOptions: [],
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.removeUpdate, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      baogong(row){
        this.$refs.baogongForm.baogongShow(row);
      },
      handleModifyUser(row){
        this.$refs.modifyUseForm.modifyUserShow(row,this.remainCount);
      },
      handleAddUser(){
        this.$refs.addUseForm.addUserShow(this.remainCount,this.parentId,this.money);
      },
      feipeiPeopleShow(row) {
        let that = this;
        that.queryParams.parentId = row.id;
        that.remainCount = row.remainCount;
        that.money = row.money;
        that.parentId = row.id;
        that.getList();
        that.open = true;
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.listByParentId, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
    }
  };
</script>
